import { TSkill } from "../../../Message/Db/Tables/TSkill";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { DescConfig } from "./DescConfig";
import { SkillIconInfo } from "../model/SkillIconInfo";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { Cache } from "../cache/Cache";
import { ESkillType } from "../../../Message/Public/ESkillType";
import { SkillRules } from "../rules/SkillRules";
import { ModelShowToolVo } from "../view/modelShowTool/ModelShowToolVo";
import { ModelType } from "../scene/modle/data/ModelType";
type int = number;
//class SkillConfig
    
    export  class SkillConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this._iconMap = new Map<any, any> /* flash.utils.Dictionary */();
            if (SkillConfig._instance != null) 
            {
                throw new Error(" ResConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TSkill();
                loc1.skillId = loc2.skillId;
                loc1.skillName = StringHelper.getString(loc2.skillName);
                loc1.skillIcon = StringHelper.getString(loc2.skillIcon);
                loc1.skillType = loc2.skillType;
                loc1.targetType = loc2.targetType;
                loc1.consume = loc2.consume;
                loc1.attackDistance = loc2.attackDistance;
                loc1.roleCareer = loc2.roleCareer;
                loc1.preSkillId = loc2.preSkillId;
                loc1.skillLevel = loc2.skillLevel;
                loc1.targetNumber = loc2.targetNumber;
                loc1.targetSelect = loc2.targetSelect;
                loc1.range = loc2.range;
                loc1.levelLimited = loc2.levelLimited;
                loc1.useType = loc2.useType;
                loc1.triggerProbability = loc2.triggerProbability;
                loc1.hitProbability = loc2.hitProbability;
                loc1.leadTime = loc2.leadTime;
                loc1.leadCount = loc2.leadCount;
                loc1.useTime = loc2.useTime;
                loc1.hurtEffect = loc2.hurtEffect;
                loc1.specialEffect = loc2.specialEffect;
                loc1.specialCorrespondingState = loc2.specialCorrespondingState;
                loc1.correspondingEffect = loc2.correspondingEffect;
                loc1.additionProbability = loc2.additionProbability;
                loc1.additionState = loc2.additionState;
                loc1.correspondingWeapon = loc2.correspondingWeapon;
                loc1.consumeMaterial = loc2.consumeMaterial;
                loc1.needSkillBook = loc2.needSkillBook;
                loc1.needExperience = loc2.needExperience;
                loc1.needCoin = loc2.needCoin;
                loc1.needVitalEnergy = loc2.needVitalEnergy;
                loc1.cooldownTime = loc2.cooldownTime;
                loc1.skillDescription = loc2.skillDescription;
                loc1.skillAction = loc2.skillAction;
                loc1.skillEffect = loc2.skillEffect;
                loc1.posType = loc2.posType;
                loc1.guildSchoolLevel = loc2.guildSchoolLevel;
                loc1.needGuildMoney = loc2.needGuildMoney;
                loc1.needGuildContribution = loc2.needGuildContribution;
                loc1.ignoreState = loc2.ignoreState;
                loc1.descId = loc2.descId;
                loc1.notBeginFight = loc2.notBeginFight;
                if (loc1 && loc1.descId > 0) 
                {
                    loc1.skillDescription = DescConfig.instance.getDescAlyzObj(loc1.descId, loc1);
                }
                this._map[loc1.skillId] = loc1;
            }
            return;
        }

        /* internal  */writeIcon(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new SkillIconInfo();
                loc1.career = loc2.career;
                loc1.posType = loc2.posType;
                loc1.iconType = loc2.type;
                this._iconMap[loc1.career + "_" + loc1.posType] = loc1;
            }
            return;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_skill.json");
            this.write(loc1);
            loc1 = ConfigManager.instance.getJSONByFileName("t_skill_icon.json");
            this.writeIcon(loc1);
            return;
        }

        public getInfoByName(arg1: int): TSkill
        {
            return this._map[arg1];
        }

        public getNextInfo(arg1: TSkill): TSkill
        {
            var loc1=null;
            var loc2=0;
            if (arg1) 
            {
                loc2 = Cache.instance.role.careerEnabled;
                var loc3=0;
                var loc4=this._map;
                for(loc1 of loc4) 
                {
                    if (!(loc1.roleCareer == arg1.roleCareer && !((loc1.roleCareer & loc2) == 0) && arg1.posType == loc1.posType && loc1.skillLevel == arg1.skillLevel + 1)) 
                    {
                        continue;
                    }
                    if (!(!(arg1.skillType == ESkillType._ESkillTypeMarry) || arg1.skillType == loc1.skillType)) 
                    {
                        continue;
                    }
                    return loc1;
                }
            }
            return null;
        }

        public getCareerSkills(arg1: int, arg2: int=-1): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=this._map;
            for(loc2 of loc4) 
            {
                if (!(arg2 == -1 || arg2 == loc2.skillLevel)) 
                {
                    continue;
                }
                if (!(loc2.posType > 0)) 
                {
                    continue;
                }
                if (loc2.roleCareer != arg1) 
                {
                    continue;
                }
                loc1.push(loc2);
            }
            return loc1;
        }

        public getGuildSkills(arg1: int=-1): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=Cache.instance.role.careerEnabled;
            var loc4=0;
            var loc5=this._map;
            for(loc2 of loc5) 
            {
                if (!(arg1 == -1 || arg1 == loc2.skillLevel)) 
                {
                    continue;
                }
                if (!((loc2.roleCareer == 0 || !((loc2.roleCareer & loc3) == 0)) && SkillRules.isGuildSkill(loc2))) 
                {
                    continue;
                }
                loc1.push(loc2);
            }
            return loc1;
        }

        public getMarrySkills(arg1: int=-1): Array<any>
        {
            var loc2=null;
            var loc1=[];
            var loc3=0;
            var loc4=this._map;
            for(loc2 of loc4) 
            {
                if (!(arg1 == -1 || arg1 == loc2.skillLevel)) 
                {
                    continue;
                }
                if (!SkillRules.isMarrySkill(loc2)) 
                {
                    continue;
                }
                if (!SkillRules.isMarrySkillBySex(loc2.skillId)) 
                {
                    continue;
                }
                loc1.push(loc2);
            }
            return loc1;
        }

        public getGuildSkillsByType(arg1: Boolean): Array<any>
        {
            var loc3=null;
            var loc1=[];
            var loc2=new Map<any, any> /* flash.utils.Dictionary */();
            var loc4=0;
            var loc5=this._map;
            for(loc3 of loc5) 
            {
                if (!(loc3.guildSchoolLevel > 0)) 
                {
                    continue;
                }
                if (arg1) 
                {
                    if (loc3.needGuildMoney > 0) 
                    {
                        if (!loc2[loc3.skillIcon] && loc3.skillLevel == 1) 
                        {
                            loc1.push(loc3);
                            loc2[loc3.skillIcon] = true;
                        }
                    }
                    continue;
                }
                if (loc3.needGuildMoney != 0) 
                {
                    continue;
                }
                if (!(!loc2[loc3.skillIcon] && loc3.skillLevel == 1)) 
                {
                    continue;
                }
                loc1.push(loc3);
                loc2[loc3.skillIcon] = true;
            }
            return loc1;
        }

        public getIconType(arg1: int, arg2: int): SkillIconInfo
        {
            var loc1=arg1 + "_" + arg2;
            if (this._iconMap.hasOwnProperty(loc1)) 
            {
                return this._iconMap[loc1];
            }
            return null;
        }

        public isRangeSkill(arg1: int, arg2: int): Boolean
        {
            var loc2=null;
            var loc1=arg1 + "_" + arg2;
            if (this._iconMap.hasOwnProperty(loc1)) 
            {
                if ((loc2 = this._iconMap[loc1] as SkillIconInfo).iconType == 1) 
                {
                    return true;
                }
            }
            return false;
        }

        public isSpecialSkill(arg1: int): Boolean
        {
            var loc1=this._map[arg1] as TSkill;
            return loc1 && loc1.posType == 1;
        }

        public isSpecialBookSkill(arg1: int): Boolean
        {
            var loc1=this._map[arg1] as TSkill;
            return loc1 && loc1.posType == 1 && loc1.skillLevel == 1;
        }

        public getSkillName(arg1: int): string
        {
            var loc1=this._map[arg1] as TSkill;
            if (loc1) 
            {
                return loc1.skillName;
            }
            return "";
        }

        public getSkillLevel(arg1: int): int
        {
            var loc1=this._map[arg1] as TSkill;
            if (loc1) 
            {
                return loc1.skillLevel;
            }
            return 0;
        }

        public SkillConfig.get allSkills(): Array<any>
        {
            var loc2=null;
            var loc4=null;
            var loc5=null;
            var loc1="";
            var loc3=[];
            var loc6=0;
            var loc7=this._map;
            for (loc5 in loc7) 
            {
                loc2 = TSkill(this._map[loc5]).skillEffect.toString();
                if (!(int(loc2) > 0 && loc1.indexOf(loc2) == -1)) 
                {
                    continue;
                }
                loc1 = loc1 + (loc2 + ",");
                (loc4 = new ModelShowToolVo()).id = TSkill(this._map[loc5]).skillEffect.toString();
                loc4.modelType = ModelType.Skill;
                loc3.push(loc4);
            }
            return loc3;
        }

        public static get instance(): SkillConfig
        {
            if (SkillConfig._instance == null) 
            {
                SkillConfig._instance = new SkillConfig();
            }
            return SkillConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_iconMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: SkillConfig;
    }
